<?php
echo $header;
echo $column_left;
echo $column_right;
$width_content = '100%';
if (($column_left) && ($column_right)) {
    $width_content = '48%';
} elseif (($column_left) || ($column_right)) {
    $width_content = '74%';
}
$style = '';
if ($column_left) {
    $style .= '; margin-left:1%';
}
if ($column_right) {
    $style .= '; margin-right:1%';
}
?>
<div class="content" style="width:<?php echo $width_content . $style; ?>"><?php echo $content_top; ?>
    <div class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
            <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
        <?php } ?>
    </div>
    <ul data-role="listview" data-divider-theme="a">
        <li data-role="list-divider"><h1><?php echo $heading_title; ?></h1></li>
    </ul><br />
    <ul data-role="listview" data-divider-theme="a">
        <li data-role="list-divider"><?php echo $text_critea; ?></li>
        <li><div data-role="fieldcontain">
                <p><?php echo $entry_search; ?>
                    <?php if ($filter_name) { ?>
                        <input type="text" name="filter_name" value="<?php echo $filter_name; ?>" />
                    <?php } else { ?>
                        <input type="text" name="filter_name" value="<?php echo $filter_name; ?>" onclick="this.value = '';" onkeydown="this.style.color = '000000'" style="color: #999;" />
                    <?php } ?>
                    <select name="filter_category_id">
                        <option value="0"><?php echo $text_category; ?></option>
                        <?php foreach ($categories as $category_1) { ?>
                            <option value="<?php echo $category_1['category_id']; ?>"<?php echo ($category_1['category_id'] == $filter_category_id ? ' selected="selected"' : ''); ?>><?php echo $category_1['name']; ?></option>
                            <?php foreach ($category_1['children'] as $category_2) { ?>
                                <option value="<?php echo $category_2['category_id']; ?>"<?php echo ($category_2['category_id'] == $filter_category_id ? ' selected="selected"' : ''); ?>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $category_2['name']; ?></option>
                                <?php foreach ($category_2['children'] as $category_3) { ?>
                                    <option value="<?php echo $category_3['category_id']; ?>"<?php echo ($category_3['category_id'] == $filter_category_id ? ' selected="selected"' : ''); ?>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $category_3['name']; ?></option>
                                <?php } ?>
                            <?php } ?>
                        <?php } ?>
                    </select>
                    <input type="checkbox" name="filter_sub_category" value="1" id="sub_category"<?php echo ($filter_sub_category ? ' checked="checked"' : ''); ?> />
                    <label for="sub_category"><?php echo $text_sub_category; ?></label>
                    <input type="checkbox" name="filter_description" value="1" id="description"<?php echo ($filter_description ? ' checked="checked"' : ''); ?> />
                    <label for="description"><?php echo $entry_description; ?></label>
                </p>
            </div>
        </li>
    </ul>
    <div class="buttons">
        <div class="right"><a data-role="button" id="button-search" class="button"><span><?php echo $button_search; ?></span></a></div>
    </div><br />
    <ul data-role="listview" data-divider-theme="a">
        <li data-role="list-divider"><?php echo $text_search; ?></li>
    </ul>
    <?php if ($products) { ?>
        <div class="product-filter">
            <div data-role="fieldcontain" class="limit">
                <select onchange="location = this.value;" data-native-menu="false">
                    <?php foreach ($limits as $limits) { ?>
                        <option value="<?php echo $limits['href']; ?>"<?php echo (($limits['value'] == $limit) ? ' selected="selected"' : ''); ?>><?php echo $text_limit . ' ' . $limits['text']; ?></option>
                    <?php } ?>
                </select>
            </div>

            <div data-role="fieldcontain" class="sort">
                <select onchange="location = this.value;" data-native-menu="false">
                    <?php foreach ($sorts as $sorts) { ?>
                        <option value="<?php echo $sorts['href']; ?>"<?php echo (($sorts['value'] == $sort . '-' . $order) ? ' selected="selected"' : ''); ?>><?php echo $text_sort . ' ' . $sorts['text']; ?></option>
                    <?php } ?>
                </select>
            </div>
        </div>
        <div class="product-compare"><a data-role="button" href="<?php echo $compare; ?>" id="compare-total"><?php echo $text_compare; ?></a></div>
        <ul data-role="listview" data-divider-theme="a" class="product-list">
            <li data-role="list-divider"><?php echo $heading_title; ?></li>
            <?php foreach ($products as $product) { ?>
                <li><a href="<?php echo $product['href']; ?>">
                        <?php if ($product['thumb']) { ?>
                            <img class="image" src="<?php echo $product['thumb']; ?>" title="<?php echo $product['name']; ?>" alt="<?php echo $product['name']; ?>" />
                        <?php } ?>
                        <h3><?php echo $product['name']; ?></h3>
                        <div><span class="description"><?php echo $product['description']; ?></span><br />
                            <?php if ($product['price']) { ?>
                            <div class="price">
                                <?php if (!$product['special']) { ?>
                                    <?php echo $product['price']; ?>
                                <?php } else { ?>
                                    <span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
                                <?php } ?>
                                <?php if ($product['tax']) { ?>
                                    &nbsp;&nbsp;&nbsp;<span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span>
                                <?php } ?>
                            </div>
                        <?php } ?>
                        <?php if ($product['rating']) { ?>
                            <div class="rating"><img src="catalog/view/theme/mobile/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo $product['reviews']; ?>" /></div>
                        <?php } ?>
                        </div>
                    </a>
                    <a href="#" onclick="addToCart('<?php echo $product['product_id']; ?>');" data-rel="dialog" data-transition="slideup"><?php echo $button_cart; ?></a></li>
            <?php } ?>
        </ul><br />
        <div class="pagination"><?php echo $pagination; ?></div>
    <?php } else { ?>
        <div class="content"><?php echo $text_empty; ?></div>
    <?php } ?>
    <?php echo $content_bottom; ?></div>
<script type="text/javascript"><!--
    $('#content input[name=\'filter_name\']').keydown(function(e) {
        if (e.keyCode == 13) {
            $('#button-search').trigger('click');
        }
    });

    $('#button-search').bind('click', function() {
        url = 'index.php?route=product/search';

        var filter_name = $('.content input[name=\'filter_name\']').attr('value');

        if (filter_name) {
            url += '&filter_name=' + encodeURIComponent(filter_name);
        }

        var filter_category_id = $('.content select[name=\'filter_category_id\']').attr('value');

        if (filter_category_id > 0) {
            url += '&filter_category_id=' + encodeURIComponent(filter_category_id);
        }

        var filter_sub_category = $('.content input[name=\'filter_sub_category\']:checked').attr('value');

        if (filter_sub_category) {
            url += '&filter_sub_category=true';
        }

        var filter_description = $('.content input[name=\'filter_description\']:checked').attr('value');

        if (filter_description) {
            url += '&filter_description=true';
        }

        location = url;
    });


    //--></script>
<?php echo $footer; ?>